$(function(){
	$.get('/material/getIndustries',function(result){
		var industryList = result.industryList;
		for(i=0;i<industryList.length;i++){
			$('#selIndustry').append('<option class="select-lucency" value="'+industryList[i].id+'">'
					+industryList[i].industry+'</option>');
		}
	})
	// 输入行数
	$("#add_root").keyup(function(e){
		var textareaText = $("#add_root").val();
		var textBr = textareaText.split("\n");
		//监听键盘回收键
		if (e.keyCode == 13) {
			var number = $("#begin").text();
			var newNumber;
			newNumber = parseInt(number) - 1;
			$("#begin").text(newNumber);
		}
		if (textBr.length > 10){
			$(".tc-btn").addClass("disable");
		} else {
			if (textareaText != "") {
				$(".tc-btn").removeClass("disable");
			} else {
				$(".tc-btn").addClass("disable");
			}
		}	
	})
	//点击开始拓词
	$("#begin_junbros").click(function(){
		
		var keywordstr = "";
		var inversestr = "";
		var industryId = "";
		//行业
		industryId = $("#selIndustry option:selected").val();	
		/*  if(industryId==null||industryId==""||industryId=="请选择行业"){
			alert("请选择行业");
			return;
		} */ 
		//词根
		var text = $("#add_root").val();
		if(text==null||text==""){
			alert("请输入词根");
			return;
		}
		var arry = text.split("\n");
		for(i in arry){
			keywordstr = keywordstr + arry[i] + ",";
		}
		keywordstr = keywordstr.substring(0,keywordstr.length-1);
		//过滤词
		var inverseWord = $('#deny_word').val();
		var arry2 = inverseWord.split("\n");
		for(i in arry2){
			inversestr = inversestr + arry2[i] + ",";
		}
		inversestr = inversestr.substring(0,inversestr.length-1);
		
		
		//var url = encodeURI("page/sectionalization.html?industryId="+industryId+"&keywordstr="+keywordstr+"&inversestr="+inversestr);
		var url = encodeURI("../../page/sectionalization.html");
		if (arry.length < 10 && text != "") {
			// alert("成功");
			
	            //window.location.href=url;
	            $.post('sectionalization',
	            		{
	            			industryId:industryId,
	            			keywordstr:keywordstr,
	            			inversestr:inversestr
	            		},
	            		function(result){
	            			if(result.result=="success"){
	            				window.location.href=url;
	            			}else{
	            				alert("请输入关键词信息");
	            			}
	            			
	            })
	           
		}
	})
	//获取否定词   最多可输入100个否定词
	$("#deny_word").keyup(function(e){
		var denyText = $("#deny_word").val();
		var textBr = denyText.split("\n");
		if (e.keyCode == 13) {
			var number = $("#word_number").text();
			var newNumber;
			newNumber = parseInt(number) - 1;
			$("#word_number").text(newNumber);
		}
		if (textBr.length > 100){
			$(".negtive-warn").css("display","inline-block");
		}
	})
	function setIfOpen(val) {
	    document.cookie = "ifOpen=" + val;
	  }

	  function getIfOpenVal(param) {
	    var strCookie = document.cookie;
	    var arrCookie = strCookie.split(";");
	    for (var i = 0; i < arrCookie.length; i++) {
	      var arr = arrCookie[i].split("=");
	      if (arr[0] == param)
	        return arr[1];
	    }
	    return null;
	  }
	  // 收缩服务
	  var ifOpen = getIfOpenVal("ifOpen");
	  
	  // index页面默认展开浮窗
	  if(ifOpen == 0){
	    $(".business-bridge-iframe").animate({
	      left : "-230px",
	    }, 0)
	    $(".js-shrink-button").find("span").removeClass("control").text("服务指导");
	    
	    $(".js-shrink-button").toggle(function() {
	      $(".business-bridge-iframe").animate({
	        left : "0px",
	      }, 1000)
	      $(this).find("span").addClass("control").text("收起");
	      setIfOpen(1);
	    }, function() {

	      $(".business-bridge-iframe").animate({
	        left : "-230px",
	      }, 1000)
	      $(this).find("span").removeClass("control").text("服务指导");
	      setIfOpen(0);
	    })
	  }else{

	    $(".js-shrink-button").toggle(function() {
	      $(".business-bridge-iframe").animate({
	        left : "-230px",
	      }, 1000)
	      $(this).find("span").removeClass("control").text("服务指导");
	      setIfOpen(0);
	    }, function() {

	      $(".business-bridge-iframe").animate({
	        left : "0px",
	      }, 1000)
	      $(this).find("span").addClass("control").text("收起");
	      setIfOpen(1);
	    })
	  }

	  
	  var t1 = null;
	    // 获取验证码
	    $("#acquireCode").click(function(){
	        var jsPhone = $(".js-phone").val();
	        if (jsPhone == ""){
	            alert("请输入手机号码");
	        } else if (!(/^1[34578]\d{9}$/.test(jsPhone))) {
	            alert("手机格式不对");
	        } else {
	        	$.post('/sendIdentify',
	            		{jsPhone:jsPhone},	
	            		function(result){
	            		if(result.result=="error"){
	            			alert("验证码发送失败,请在60秒后重试");
	            		}
	            	});
	            countdown($(this));
	        }
	    })

	    $(".js-register").click(function(){
	        var jsPhone = $(".js-phone").val();
	        var jsVerification = $(".js-verification").val();
	        if (jsPhone == "" || jsVerification == "") {
	            alert("手机或验证码输入错误");
	        } else {
	        	$.post('/checkIdentify',
	            		{jsVerification:jsVerification},	
	            		function(result){
	            		if(result.result=="success"){
	            			$('.index-shade').hide();
	            		}else{
	            			alert("验证码过期或验证码错误");
	            		}
	            	})
	        }
	    })

	    function countdown(obj) {
	        var count = 60;
	        $(obj).css({ background: '#e7e7e7' }).val(count.toString() + "秒").attr('disabled', 'disabled');

	        var doCount = function () {
	            if (--count < 1) {
	                var t2 = clearInterval(t1);
	                $(obj).css({ background: '#e7e7e7' }).val('重新发送').removeAttr('disabled');
	            }
	            else {
	                $(obj).val(count.toString() + "秒");
	            }
	        };

	        t1 = setInterval(function () { doCount(); }, 1000);

	    }
})